﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using Jungle.Code.Utils;
using Jungle.Prodamo.AdvertManager;
using Jungle.Prodamo.Core;

namespace Jungle.Prodamo.User.WebControls
{
    public class Estims : WebControl
    {
        private int estimType;
        private int itemId;

        public int EstimType { get { return estimType; } set { estimType = value; } }
        public int ItemId { get { return itemId; } set { itemId = value; } }
        protected override void RenderContents(HtmlTextWriter writer)
        {
 
            writer.AddAttribute("class", "advm_table");
            writer.RenderBeginTag(HtmlTextWriterTag.Table);
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.AddAttribute("class", "advm_td");
            writer.AddAttribute("colspan", "2");
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            writer.Write("Отзывы пользователей");
            writer.RenderEndTag();
            writer.RenderEndTag();

            Estimation estims = new Estimation();
            estims.EstimType = estimType;
            estims.ItemId = itemId;
            estims.GetCurrent();
            bool c = true;
            foreach(Estimation e in estims.EstimList)
            {
                UserManager um = new UserManager();
                um.UserId = e.UserId;
                um.GetById();

                if (!c)
                {
                    writer.AddAttribute("style", "background-color: #F1F1F1;");
                    c = true;
                }
                else c = false;
                writer.RenderBeginTag(HtmlTextWriterTag.Span);

                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.AddAttribute("class", "advm_td");
                writer.AddAttribute("colspan", "2");
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write(e.PubDate + " " + um.UserLink());
                writer.RenderEndTag();
                writer.RenderEndTag();

                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write("Понравилось");
                writer.RenderEndTag();
                writer.AddAttribute("style", "color: Green;");
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write(e.Advant);
                writer.RenderEndTag();
                writer.RenderEndTag();

                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write("Не понравилось");
                writer.RenderEndTag();
                writer.AddAttribute("style", "color: Red;");
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write(e.Faling);
                writer.RenderEndTag();
                writer.RenderEndTag();

                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write("Общее мнение");
                writer.RenderEndTag();
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write(e.Description);
                writer.RenderEndTag();
                writer.RenderEndTag();

                if (estimType == 0)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.Write("Время использывания");
                    writer.RenderEndTag();
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.Write(e.TimeUse);
                    writer.RenderEndTag();
                    writer.RenderEndTag();

                    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.Write("Место покупки");
                    writer.RenderEndTag();
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.Write(e.BuyPlace);
                    writer.RenderEndTag();
                    writer.RenderEndTag(); 
                }

                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write("Совет другим");
                writer.RenderEndTag();
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                if (e.Advice) writer.Write("Да советую");
                else writer.Write("Нет не советую");
                writer.RenderEndTag();
                writer.RenderEndTag();

                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write("Оценка");
                writer.RenderEndTag();
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write(e.Raiting);
                writer.RenderEndTag();
                writer.RenderEndTag();

                writer.RenderEndTag();
            }


            writer.RenderEndTag(); 
            base.RenderContents(writer);
        }
    }
}
